<template>
  <div>
    <achievementPreview
      v-model="ModelVisible"
      :id="achievemenId"
      :procInsId="achievemenprocInsId"
      :isView="isView"
      :type="achievementype"
      @callBack="refresh"
    />

    <peopleDetails :activ="activ" :obj="obj" @close-dialog="activ = false"></peopleDetails>

    <UnitModal
      :opType="opType"
      :opUnitId="opUnitId"
      v-model="unitModalVisible"
      v-if="unitModalVisible"
      @refreshUnitList="refresh"
    />
    <CheckModal ref="checkModalRef" @save-success="refresh" />
    <ViewModal ref="viewModalRef" />
    <ViewProject ref="viewProjectRef" />
    <ViewLlscModal ref="viewLlscModalRef" />
    <CheckLlscModal ref="checkLlscModalRef" @check-success="refresh" />
    <ViewKyfwModal ref="viewKyfwModalRef" />
    <CheckKyfwModal ref="checkKyfwModalRef" @check-success="refresh" />
    <OperateKycxModal ref="operateKycxModal" @check-success="refresh" />
    <CheckProject ref="checkProjectRef" @check-success="refresh" />
    <OperateProject ref="operateProjectRef" @check-success="refresh" />
    <detailsjfdzDialog ref="opendetailsjfdzDialog" @success="refresh"> </detailsjfdzDialog>
    <!--    经费外拨审核-->
    <audit ref="openaudit" @success="refresh" />
    <JfwbDetails
      ref="JfwbDetailsRef"
      :visible="JfwbDialogcompile"
      :projectOptions="projectOptions"
      :compileRow="compileRow"
      :tableData="tableData"
      @getlist="refresh"
      @save="handleSave"
      @saveAndPass="handleSaveAndPass"
      @close="dialogVisible = false"
      @getselectVproject="getselectVproject"
    />
    <jfzcDialogDetails @Getlist="refresh" ref="DetailsDialog"></jfzcDialogDetails>
    <peopleDetailsAudit ref="RefpeopleDetailsAudit" @Getlist="refresh"> </peopleDetailsAudit>
  </div>
</template>

<script setup>
import ViewProject from "@/views/project/components/ViewProject"; //项目信息
import CheckProject from "@/views/project/components/CheckProject"; //审核项目
import OperateProject from "@/views/project/components/OperateProject"; //变更、中检、结项
import achievementPreview from "@/components/achievementPreview/index.vue"; //成果
import peopleDetails from "@/components/peopleDetails/peopleDetails.vue"; //人员详情
import UnitModal from "@/views/research/components/UnitModal.vue"; //科研平台
import ViewModal from "@/views/fee/rz/xmrzbl/components/ViewModal.vue";
import CheckModal from "@/views/fee/rz/xmrzbl/components/CheckModal.vue"; //经费认领
import detailsjfdzDialog from "@/views/money/jfdz/jfdzDetails.vue"; // 经费调账
import ViewLlscModal from "@/views/llsc/components/ViewModal.vue"; //伦理审查查看
import CheckLlscModal from "@/views/llsc/components/CheckModal.vue"; //伦理审查审核
import ViewKyfwModal from "@/views/kyfw/components/ViewModal.vue"; //科研服务查看
import CheckKyfwModal from "@/views/kyfw/components/CheckModal.vue"; //科研服务审核
import OperateKycxModal from "@/views/kycx/components/OperateModal.vue"; //科研诚信
const props = defineProps({
  isView: {
    type: Boolean,
    default: true,
  },
});
const unitModalVisible = ref(false);
const opUnitId = ref();
const viewProjectRef = ref();
const checkProjectRef = ref();
const operateProjectRef = ref();
const viewLlscModalRef = ref();
const checkLlscModalRef = ref();
const viewKyfwModalRef = ref();
const checkKyfwModalRef = ref();
const operateKycxModal = ref();
const ModelVisible = ref(false);
const achievemenId = ref("");
const achievementype = ref("");
const achievemenprocInsId = ref("");
const checkModalRef = ref("");
const viewModalRef = ref();
const opType = ref(3); //科研平台  3代表查看,2代表审核
const emit = defineEmits(["AuthorSuccess"]);
//查看人员详情
const activ = ref(false);
const obj = ref("");
const openpeopledetails = function (id) {
  activ.value = true; //传入打开弹窗
  obj.value = id; //传入id
};

//审核人员详情
const activAudit = ref(false);
const objAudit = ref("");
const openpeopledetailsAudit = function (id, close) {
  activAudit.value = close; //传入打开弹窗
  objAudit.value = id; //传入id
};
//审核调用
import peopleDetailsAudit from "@/views/resource/researcherNav/audit.vue";
const RefpeopleDetailsAudit = ref(null);

//经费认领审核
const handleCheck = (id, processInstanceId) => {
  checkModalRef.value.check(id, processInstanceId);
};
//经费认领查看
const handleView = (id) => {
  viewModalRef.value.view(id);
};

//科研平台
const openUnintInfo = (id) => {
  unitModalVisible.value = true;
  opUnitId.value = id;
  console.log(opUnitId.value, unitModalVisible.value);
};
// 经费调账
// 打开详情
const opendetailsjfdzDialog = ref(null);
const openDetails = (row, name) => {
  // 这里可以添加实际的编辑逻辑，比如弹出编辑表单等
  //compileRow.value = row;
  opendetailsjfdzDialog.value.opencompileDialog(row, name);
};
// 经费外拨
// 打开审核
import audit from "@/views/money/audit.vue";
import { ref } from "vue";
import JfwbDialogcompile from "@/views/money/jfwb/JfwbDialogcompile.vue";
import JfwbDetails from "@/views/money/jfwb/JfwbDetails.vue";
const openaudit = ref(null);
const openjfwbauditDetails = (row) => {
  // 这里可以添加实际的编辑逻辑，比如弹出编辑表单等
  //compileRow.value = row;
  openaudit.value.openaudit(row);
};
// 经费外拨
// 打开查看
const JfwbDetailsRef = ref(null);
const JfwbDetailsBtn = (row) => {
  // 这里可以添加实际的编辑逻辑，比如弹出编辑表单等
  JfwbDetailsRef.value.opencompileDialog(row);
};
// 控制弹窗显示与隐藏的变量
const dialogVisible = ref(false);

//经费支出
import jfzcDialogDetails from "@/views/money/jfzc/jfzcDialogDetails.vue";
const DetailsDialog = ref(null);
const DetailsDialogBtn = (row, name) => {
  //alert('DetailsDialogBtn')
  DetailsDialog.value.openDialog(row, name);
};
/**
 * 操作成功后刷新
 */
const refresh = () => {
  // 重新获取详情
  emit("AuthorSuccess");
};
const view = (row) => {
  switch (row.largeModule) {
    case "项目":
      const operateTypes = ["项目变更", "项目中检", "项目结项"];
      const projectTypes = ["纵向项目立项", "校级项目立项", "进账合同签订"];
      if (props.isView) {
        if (operateTypes.includes(row.moduleName)) {
          operateProjectRef.value.view(
            row.moduleName,
            row.projectId,
            row.businessId,
            row.projectType
          );
        } else if (projectTypes.includes(row.moduleName)) {
          viewProjectRef.value.view(row.businessId, row.projectType);
        } else if (row.moduleName == "出账合同签订") {
          viewProjectRef.value.view(row.businessId, "cZProject");
        } else if (row.moduleName == "申报项目") {
          viewProjectRef.value.view(row.businessId, "sbxm");
        }
      } else {
        if (operateTypes.includes(row.moduleName)) {
          operateProjectRef.value.check(
            row.moduleName,
            row.projectId,
            row.businessId,
            row.processInstanceId,
            row.projectType
          );
        } else if (projectTypes.includes(row.moduleName)) {
          checkProjectRef.value.check(row.businessId, row.projectType, row.processInstanceId);
        } else if (row.moduleName == "出账合同签订") {
          checkProjectRef.value.check(row.businessId, "cZProject", row.processInstanceId);
        } else if (row.moduleName == "申报项目") {
          checkProjectRef.value.check(row.businessId, "sbxm", row.processInstanceId);
        }
      }
      break;
    case "伦理审查":
      if (props.isView) {
        viewLlscModalRef.value.view(row.businessId);
      } else {
        checkLlscModalRef.value.check(row.businessId, row.processInstanceId);
      }
      break;
    case "科研服务":
      if (props.isView) {
        viewKyfwModalRef.value.view(row.businessId);
      } else {
        checkKyfwModalRef.value.check(row.businessId, row.processInstanceId);
      }
      break;
    case "科研诚信":
      if (props.isView) {
        operateKycxModal.value.view(row.moduleName, row.businessId);
      } else {
        operateKycxModal.value.check(row.moduleName, row.businessId, row.processInstanceId);
      }
      break;
    case "成果":
      achievemenId.value = row.businessId;
      achievementype.value = row.projectType;
      achievemenprocInsId.value = row.processInstanceId ? row.processInstanceId : "";
      ModelVisible.value = true;
      break;
    case "基础资源":
      //alert('123')
      if (props.isView) {
        // alert('  openpeopledetails(row.businessId);')
        openpeopledetails(row.businessId);
      } else {
        row.id = row.businessId;
        // console.log(row)
        RefpeopleDetailsAudit.value.openaudit(row);
      }

      break;
    case "科研平台":
      if (props.isView == false) {
        opType.value = 2;
      }
      openUnintInfo(row.businessId);
      break;
    case "经费":
      if (row.moduleName == "经费认领") {
        if (props.isView) {
          handleView(row.businessId);
        } else {
          handleCheck(row.businessId, row.processInstanceId);
        }
      } else if (row.moduleName == "经费调账") {
        if (props.isView) {
          openDetails(row, "name");
        } else {
          openDetails(row, "shenhename");
        }
      } else if (row.moduleName == "经费外拨") {
        if (props.isView) {
          JfwbDetailsBtn(row);
        } else {
          openjfwbauditDetails(row);
        }
      } else if (row.moduleName == "经费支出报销") {
        //alert('132')
        if (props.isView) {
          DetailsDialogBtn(row, "name");
          //alert('chakan')
        } else {
          DetailsDialogBtn(row, "shenhename");
          // alert('shenhe')
        }
      }
      console.log(row.moduleName);
      break;
  }
};
defineExpose({ view });
</script>

<style lang="scss" scoped></style>
